package com.szholly.pro.watergas_server.ps.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.szholly.pro.watergas_server.common.util.JsonUtil;
import com.szholly.pro.watergas_server.common.web.BaseController;
import com.szholly.pro.watergas_server.common.web.RequestUnit;
import com.szholly.pro.watergas_server.ps.service.WaterThanService;
import com.szholly.plug.form.excel.utils.StringUtil;

/**
 * 在线数据比对
 * @author wzj
 *
 */
@Controller
@RequestMapping("/WaterThanController/*")
public class WaterThanController extends BaseController{

	@Autowired
	WaterThanService waterthanservice;
	
	
	/**
	 * 获取在线数据比对
	 * @param resq
	 * @param res
	 */
	@RequestMapping("/queryWaterThan")
	public void queryWaterThan(HttpServletRequest resq, HttpServletResponse res)throws Exception{
		Map<String,String> params=queryStationQueryParams();
		List<Object> waterthandata=waterthanservice.queryWaterThan(params);
		HashMap<String,Object> data=new HashMap<>();
		data.put("waterthandata", waterthandata);
		String result=JsonUtil.ConvertObjectToJson(data);
		outString(result);
	}
	/**
	 * 盲样与抽测excel
	 * @param resq
	 * @param res
	 * @throws Exception
	 */
	@RequestMapping("/outBlindSample")
	public void outBlindSample(HttpServletRequest resq, HttpServletResponse res)throws Exception{
		Map<String,String> params=queryStationQueryParams();
		List<Object> waterthandata=waterthanservice.queryWaterThan(params);
		HashMap<String,Object> data=new HashMap<>();
		data.put("waterthandata", waterthandata);
		data.put("start", params.get("start"));
		data.put("end", params.get("end"));
		HtmlToExcel(data, "qc/blindSample.html", "盲样与抽测.xls");
	}
	/**
	 * 在线数据比对导出excel
	 * @param resq
	 * @param res
	 * @throws Exception
	 */
	@RequestMapping("/outWaterThan")
	public void outWaterThan(HttpServletRequest resq, HttpServletResponse res)throws Exception{
		Map<String,String> params=queryStationQueryParams();
		List<Object> waterthandata=waterthanservice.queryWaterThan(params);
		HashMap<String,Object> data=new HashMap<>();
		data.put("waterthandata", waterthandata);
		data.put("start", params.get("start"));
		data.put("end", params.get("end"));
		HtmlToExcel(data, "qc/waterThan.html", "数据比对.xls");
	}
	private Map<String,String> queryStationQueryParams() {
		Map<String,String> params = new HashMap<>();
		String stationid=RequestUnit.getString("STATION_ID");
		String start=RequestUnit.getString("start");
		String end=RequestUnit.getString("end");
		String thanType=RequestUnit.getString("thanType");
		params.put("stationid", stationid);
		if(StringUtil.IsNotNullOrEmpty(thanType)){
			if(thanType.equals("'all'")){
				params.put("thanType", "'1','2'");
			}else{
				params.put("thanType", thanType);
			}
		}		
		params.put("end", end);
		params.put("start", start);
		return params;
	}
}
